﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Seagull.Configuration;
using Seagull.Shell.Properties;

namespace Seagull.Shell
{
    public partial class SettingsWindow : Form
    {
        public SettingsWindow()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _pathConfig.SelectedObject = Config.Instance.PathConfig;
            _dataReadConfig.SelectedObject = Config.Instance.DataReadConfig;
            _diskSpaceMonitoringConfig.SelectedObject = Config.Instance.DiskSpaceMonitorConfig;
            _smsAlertConfig.SelectedObject = Config.Instance.SmsAlertConfig;
            _taskConfig.SelectedObject = Config.Instance.TaskConfig;
            _uiConfig.SelectedObject = Config.Instance.UIConfig;
        }

        private void _okButton_Click(object sender, EventArgs e)
        {
            try
            {
                Config.Instance.Save(ConfigurationManager.AppSettings["configFile"]);
                MessageBox.Show("修改以上配置需要重新启动软件", "保存配置");
                Application.Restart();
                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(string.Format("保存配置时发生错误，详细信息：{0}", exception.ToString()),
                    Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void _cancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}
